<template>
  <!--
    buildInfo 功能列表

    @author WeiXiaoJin
    @date 2021-06-24 11:26:14
  -->
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="项目名称" prop="artifactId">
        <el-input
          v-model="queryParams.artifactId"
          placeholder="请输入项目名称"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="所在分组" prop="groupId">
        <el-input
          v-model="queryParams.groupId"
          placeholder="请输入所在分组"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="服务端口" prop="servicePort">
        <el-input
          v-model="queryParams.servicePort"
          placeholder="请输入服务端口"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="项目域名" prop="domain">
        <el-input
          v-model="queryParams.domain"
          placeholder="请输入项目域名"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="是否检测环境" prop="checkEnv">
        <el-input
          v-model="queryParams.checkEnv"
          placeholder="请输入是否检测环境"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="是否生成demo" prop="generatorDemo">
        <el-input
          v-model="queryParams.generatorDemo"
          placeholder="请输入是否生成demo"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="jdk版本" prop="jdk">
        <el-input
          v-model="queryParams.jdk"
          placeholder="请输入jdk版本"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="包类型" prop="packageType">
        <el-input
          v-model="queryParams.packageType"
          placeholder="请输入包类型"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="中台版本号" prop="alinesnoVersion">
        <el-input
          v-model="queryParams.alinesnoVersion"
          placeholder="请输入中台版本号"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="依赖组件" prop="dependency">
        <el-input
          v-model="queryParams.dependency"
          placeholder="请输入依赖组件"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="作者名称" prop="author">
        <el-input
          v-model="queryParams.author"
          placeholder="请输入作者名称"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="作者邮箱" prop="authorEmail">
        <el-input
          v-model="queryParams.authorEmail"
          placeholder="请输入作者邮箱"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="打包语言" prop="language">
        <el-input
          v-model="queryParams.language"
          placeholder="请输入打包语言"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="打包类型" prop="deployType">
        <el-input
          v-model="queryParams.deployType"
          placeholder="请输入打包类型"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="前端中台版本" prop="alinesnoUI">
        <el-input
          v-model="queryParams.alinesnoUI"
          placeholder="请输入前端中台版本"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="仓库名称" prop="repositoryName">
        <el-input
          v-model="queryParams.repositoryName"
          placeholder="请输入仓库名称"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="业务分组" prop="gitGroupName">
        <el-input
          v-model="queryParams.gitGroupName"
          placeholder="请输入业务分组"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="仓库地址" prop="gitProjectLink">
        <el-input
          v-model="queryParams.gitProjectLink"
          placeholder="请输入仓库地址"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="仓库ID" prop="gitProjectId">
        <el-input
          v-model="queryParams.gitProjectId"
          placeholder="请输入仓库ID"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="自动化操作Token" prop="gitRunnersToken">
        <el-input
          v-model="queryParams.gitRunnersToken"
          placeholder="请输入自动化操作Token"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['business:buildInfo:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['business:buildInfo:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['business:buildInfo:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['business:buildInfo:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="buildInfoList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="项目名称" align="left" prop="artifactId" />
      <el-table-column label="所在分组" align="left" prop="groupId" />
      <el-table-column label="服务端口" align="left" prop="servicePort" />
      <el-table-column label="项目域名" align="left" prop="domain" />
      <el-table-column label="是否检测环境" align="left" prop="checkEnv" />
      <el-table-column label="是否生成demo" align="left" prop="generatorDemo" />
      <el-table-column label="jdk版本" align="left" prop="jdk" />
      <el-table-column label="包类型" align="left" prop="packageType" />
      <el-table-column label="中台版本号" align="left" prop="alinesnoVersion" />
      <el-table-column label="依赖组件" align="left" prop="dependency" />
      <el-table-column label="作者名称" align="left" prop="author" />
      <el-table-column label="作者邮箱" align="left" prop="authorEmail" />
      <el-table-column label="打包语言" align="left" prop="language" />
      <el-table-column label="打包类型" align="left" prop="deployType" />
      <el-table-column label="前端中台版本" align="left" prop="alinesnoUI" />
      <el-table-column label="仓库名称" align="left" prop="repositoryName" />
      <el-table-column label="业务分组" align="left" prop="gitGroupName" />
      <el-table-column label="仓库地址" align="left" prop="gitProjectLink" />
      <el-table-column label="仓库ID" align="left" prop="gitProjectId" />
      <el-table-column label="自动化操作Token" align="left" prop="gitRunnersToken" />
      <el-table-column label="操作" width="200" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['business:buildInfo:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['business:buildInfo:remove']"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改buildInfo对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="800px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="项目名称" prop="artifactId">
          <el-input v-model="form.artifactId" placeholder="请输入项目名称" />
        </el-form-item>
        <el-form-item label="所在分组" prop="groupId">
          <el-input v-model="form.groupId" placeholder="请输入所在分组" />
        </el-form-item>
        <el-form-item label="服务端口" prop="servicePort">
          <el-input v-model="form.servicePort" placeholder="请输入服务端口" />
        </el-form-item>
        <el-form-item label="项目域名" prop="domain">
          <el-input v-model="form.domain" placeholder="请输入项目域名" />
        </el-form-item>
        <el-form-item label="是否检测环境" prop="checkEnv">
          <el-input v-model="form.checkEnv" placeholder="请输入是否检测环境" />
        </el-form-item>
        <el-form-item label="是否生成demo" prop="generatorDemo">
          <el-input v-model="form.generatorDemo" placeholder="请输入是否生成demo" />
        </el-form-item>
        <el-form-item label="jdk版本" prop="jdk">
          <el-input v-model="form.jdk" placeholder="请输入jdk版本" />
        </el-form-item>
        <el-form-item label="包类型" prop="packageType">
          <el-input v-model="form.packageType" placeholder="请输入包类型" />
        </el-form-item>
        <el-form-item label="中台版本号" prop="alinesnoVersion">
          <el-input v-model="form.alinesnoVersion" placeholder="请输入中台版本号" />
        </el-form-item>
        <el-form-item label="依赖组件" prop="dependency">
          <el-input v-model="form.dependency" placeholder="请输入依赖组件" />
        </el-form-item>
        <el-form-item label="作者名称" prop="author">
          <el-input v-model="form.author" placeholder="请输入作者名称" />
        </el-form-item>
        <el-form-item label="作者邮箱" prop="authorEmail">
          <el-input v-model="form.authorEmail" placeholder="请输入作者邮箱" />
        </el-form-item>
        <el-form-item label="打包语言" prop="language">
          <el-input v-model="form.language" placeholder="请输入打包语言" />
        </el-form-item>
        <el-form-item label="打包类型" prop="deployType">
          <el-input v-model="form.deployType" placeholder="请输入打包类型" />
        </el-form-item>
        <el-form-item label="前端中台版本" prop="alinesnoUI">
          <el-input v-model="form.alinesnoUI" placeholder="请输入前端中台版本" />
        </el-form-item>
        <el-form-item label="仓库名称" prop="repositoryName">
          <el-input v-model="form.repositoryName" placeholder="请输入仓库名称" />
        </el-form-item>
        <el-form-item label="业务分组" prop="gitGroupName">
          <el-input v-model="form.gitGroupName" placeholder="请输入业务分组" />
        </el-form-item>
        <el-form-item label="仓库地址" prop="gitProjectLink">
          <el-input v-model="form.gitProjectLink" placeholder="请输入仓库地址" />
        </el-form-item>
        <el-form-item label="仓库ID" prop="gitProjectId">
          <el-input v-model="form.gitProjectId" placeholder="请输入仓库ID" />
        </el-form-item>
        <el-form-item label="自动化操作Token" prop="gitRunnersToken">
          <el-input v-model="form.gitRunnersToken" placeholder="请输入自动化操作Token" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listBuildInfo, getBuildInfo, delBuildInfo, addBuildInfo, updateBuildInfo, exportBuildInfo } from "./api" ;

export default {
  name: "BuildInfo",
  components: {
  },
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // buildInfo表格数据
      buildInfoList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        artifactId: null,
        groupId: null,
        servicePort: null,
        domain: null,
        checkEnv: null,
        generatorDemo: null,
        jdk: null,
        packageType: null,
        alinesnoVersion: null,
        dependency: null,
        author: null,
        authorEmail: null,
        language: null,
        deployType: null,
        alinesnoUI: null,
        repositoryName: null,
        gitGroupName: null,
        gitProjectLink: null,
        gitProjectId: null,
        gitRunnersToken: null
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        artifactId: [
          { required: true, message: "项目名称不能为空", trigger: "blur" }
        ],
        groupId: [
          { required: true, message: "所在分组不能为空", trigger: "blur" }
        ],
        servicePort: [
          { required: true, message: "服务端口不能为空", trigger: "blur" }
        ],
        domain: [
          { required: true, message: "项目域名不能为空", trigger: "blur" }
        ],
        checkEnv: [
          { required: true, message: "是否检测环境不能为空", trigger: "blur" }
        ],
        generatorDemo: [
          { required: true, message: "是否生成demo不能为空", trigger: "blur" }
        ],
        jdk: [
          { required: true, message: "jdk版本不能为空", trigger: "blur" }
        ],
        packageType: [
          { required: true, message: "包类型不能为空", trigger: "blur" }
        ],
        alinesnoVersion: [
          { required: true, message: "中台版本号不能为空", trigger: "blur" }
        ],
        dependency: [
          { required: true, message: "依赖组件不能为空", trigger: "blur" }
        ],
        author: [
          { required: true, message: "作者名称不能为空", trigger: "blur" }
        ],
        authorEmail: [
          { required: true, message: "作者邮箱不能为空", trigger: "blur" }
        ],
        language: [
          { required: true, message: "打包语言不能为空", trigger: "blur" }
        ],
        deployType: [
          { required: true, message: "打包类型不能为空", trigger: "blur" }
        ],
        alinesnoUI: [
          { required: true, message: "前端中台版本不能为空", trigger: "blur" }
        ],
        repositoryName: [
          { required: true, message: "仓库名称不能为空", trigger: "blur" }
        ],
        gitGroupName: [
          { required: true, message: "业务分组不能为空", trigger: "blur" }
        ],
        gitProjectLink: [
          { required: true, message: "仓库地址不能为空", trigger: "blur" }
        ],
        gitProjectId: [
          { required: true, message: "仓库ID不能为空", trigger: "blur" }
        ],
        gitRunnersToken: [
          { required: true, message: "自动化操作Token不能为空", trigger: "blur" }
        ]
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询buildInfo列表 */
    getList() {
      this.loading = true;
      listBuildInfo(this.queryParams).then(response => {
        this.buildInfoList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        artifactId: null,
        groupId: null,
        servicePort: null,
        domain: null,
        checkEnv: null,
        generatorDemo: null,
        jdk: null,
        packageType: null,
        alinesnoVersion: null,
        dependency: null,
        author: null,
        authorEmail: null,
        language: null,
        deployType: null,
        alinesnoUI: null,
        repositoryName: null,
        gitGroupName: null,
        gitProjectLink: null,
        gitProjectId: null,
        gitRunnersToken: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.artifactId)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加buildInfo";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const artifactId = row.artifactId || this.ids
      getBuildInfo(artifactId).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改buildInfo";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.artifactId != null) {
            updateBuildInfo(this.form).then(response => {
              this.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addBuildInfo(this.form).then(response => {
              this.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const artifactIds = row.artifactId || this.ids;
      this.$confirm('是否确认删除buildInfo编号为"' + artifactIds + '"的数据项?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(function() {
          return delBuildInfo(artifactIds);
        }).then(() => {
          this.getList();
          this.msgSuccess("删除成功");
        })
    },
    /** 导出按钮操作 */
    handleExport() {
      const queryParams = this.queryParams;
      this.$confirm('是否确认导出所有buildInfo数据项?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(function() {
          return exportBuildInfo(queryParams);
        }).then(response => {
          this.download(response.msg);
        })
    }
  }
};
</script>
